import pymysql

# 创建一个连接
conn = pymysql.connect(host="localhost",
                       port=3306,
                       user="root",
                       password="root",
                       database="test",
                       charset="utf8")

# 获取游标，执行sql语句
cursor = conn.cursor()

# sql语句
sql = "select * from students;"

# 返回影响的行数
row_count = cursor.execute(sql)
print("执行sql语句影响的行数为：", row_count)

# 通过游标获取查询结果
# result = cursor.fetchone()
result = cursor.fetchall()
for row in result:
    print(row)

# 关闭游标
cursor.close()

# 关闭连接
conn.close()